package handler

import (
	"bytes"
	"fmt"
	// "net/http"
)

const (
	helpBodyH = `<html>
<table border="1">

<tr>
<td>接口路径</td>
<td>帮助说明</td>
</tr>
`
	helpBodyE = `</table>
</html>`

	lineTmp = `<tr>
<td>%s</td>
<td>%s</td>
</tr>`
)

func (handler *Handler) addHelper() {
}

func (handler *Handler) Helper() string {
	return "显示帮助页面"
}

func (handler *Handler) HandlerFunc(c *Context) *Respone {
	buf := bytes.NewBuffer(nil)
	buf.WriteString(helpBodyH)

	for r, h := range handler.handlerSs {
		buf.WriteString(fmt.Sprintf(lineTmp, r, h.Helper()))
	}

	for r, _ := range handler.handlers {
		buf.WriteString(fmt.Sprintf(lineTmp, r, ""))
	}

	buf.WriteString(helpBodyE)

	c.W.Write(buf.Bytes())
	return nil
}
